home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-2 / Inter.Net 55-2.iso / Mandrake / mdkinst / usr / lib / perl5 / 5.00503 / i386-linux / DynaLoader.pm < prev    next >
Encoding:
Perl POD Document  |  2000-01-12  |  7.1 KB  |  201 lines

  1.  
  2. # Generated from DynaLoader.pm.PL (resolved %Config::Config values)
  3.  
  4. package DynaLoader;
  5.  
  6. #   And Gandalf said: 'Many folk like to know beforehand what is to
  7. #   be set on the table; but those who have laboured to prepare the
  8. #   feast like to keep their secret; for wonder makes the words of
  9. #   praise louder.'
  10.  
  11. #   (Quote from Tolkien sugested by Anno Siegel.)
  12. #
  13. # See pod text at end of file for documentation.
  14. # See also ext/DynaLoader/README in source tree for other information.
  15. #
  16. # Tim.Bunce@ig.co.uk, August 1994
  17.  
  18. $VERSION = $VERSION = "1.03";    # avoid typo warning
  19.  
  20. require AutoLoader;
  21. *AUTOLOAD = \&AutoLoader::AUTOLOAD;
  22.  
  23. # The following require can't be removed during maintenance
  24. # releases, sadly, because of the risk of buggy code that does 
  25. # require Carp; Carp::croak "..."; without brackets dying 
  26. # if Carp hasn't been loaded in earlier compile time. :-( 
  27. # We'll let those bugs get found on the development track.
  28. require Carp if $] < 5.00450; 
  29.  
  30.  
  31. # enable debug/trace messages from DynaLoader perl code
  32. $dl_debug = $ENV{PERL_DL_DEBUG} || 0 unless defined $dl_debug;
  33.  
  34. #
  35. # Flags to alter dl_load_file behaviour.  Assigned bits:
  36. #   0x01  make symbols available for linking later dl_load_file's.
  37. #         (only known to work on Solaris 2 using dlopen(RTLD_GLOBAL))
  38. #         (ignored under VMS; effect is built-in to image linking)
  39. #
  40. # This is called as a class method $module->dl_load_flags.  The
  41. # definition here will be inherited and result on "default" loading
  42. # behaviour unless a sub-class of DynaLoader defines its own version.
  43. #
  44.  
  45. sub dl_load_flags { 0x00 }
  46.  
  47. # ($dl_dlext, $dlsrc)
  48. #         = @Config::Config{'dlext', 'dlsrc'};
  49.   ($dl_dlext, $dlsrc) = ('so','dl_dlopen.xs')
  50. ;
  51. # Some systems need special handling to expand file specifications
  52. # (VMS support by Charles Bailey <bailey@HMIVAX.HUMGEN.UPENN.EDU>)
  53. # See dl_expandspec() for more details. Should be harmless but
  54. # inefficient to define on systems that don't need it.
  55. $do_expand = $Is_VMS = $^O eq 'VMS';
  56.  
  57. @dl_require_symbols = ();       # names of symbols we need
  58. @dl_resolve_using   = ();       # names of files to link with
  59. @dl_library_path    = ();       # path to look for files
  60. @dl_librefs         = ();       # things we have loaded
  61. @dl_modules         = ();       # Modules we have loaded
  62.  
  63. # This is a fix to support DLD's unfortunate desire to relink -lc
  64. @dl_resolve_using = dl_findfile('-lc') if $dlsrc eq "dl_dld.xs";
  65.  
  66. # Initialise @dl_library_path with the 'standard' library path
  67. # for this platform as determined by Configure
  68.  
  69. # push(@dl_library_path, split(' ', $Config::Config{'libpth'});
  70. push(@dl_library_path, split(' ', '/usr/local/lib /lib /usr/lib'));
  71.  
  72. # Add to @dl_library_path any extra directories we can gather from
  73. # environment variables. So far LD_LIBRARY_PATH is the only known
  74. # variable used for this purpose. Others may be added later.
  75. push(@dl_library_path, split(/:/, $ENV{LD_LIBRARY_PATH}))
  76.     if $ENV{LD_LIBRARY_PATH};
  77.  
  78.  
  79. # No prizes for guessing why we don't say 'bootstrap DynaLoader;' here.
  80. boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) &&
  81.                                 !defined(&dl_load_file);
  82.  
  83.  
  84. if ($dl_debug) {
  85.     print STDERR "DynaLoader.pm loaded (@INC, @dl_library_path)\n";
  86.     print STDERR "DynaLoader not linked into this perl\n"
  87.         unless defined(&boot_DynaLoader);
  88. }
  89.  
  90. 1; # End of main code
  91.  
  92.  
  93. sub croak   { require Carp; Carp::croak(@_)   }
  94.  
  95. # The bootstrap function cannot be autoloaded (without complications)
  96. # so we define it here:
  97.  
  98. sub bootstrap {
  99.     # use local vars to enable $module.bs script to edit values
  100.     local(@args) = @_;
  101.     local($module) = $args[0];
  102.     local(@dirs, $file);
  103.  
  104.     unless ($module) {
  105.     require Carp;
  106.     Carp::confess("Usage: DynaLoader::bootstrap(module)");
  107.     }
  108.  
  109.     # A common error on platforms which don't support dynamic loading.
  110.     # Since it's fatal and potentially confusing we give a detailed message.
  111.     croak("Can't load module $module, dynamic loading not available in this perl.\n".
  112.     "  (You may need to build a new perl executable which either supports\n".
  113.     "  dynamic loading or has the $module module statically linked into it.)\n")
  114.     unless defined(&dl_load_file);
  115.  
  116.     my @modparts = split(/::/,$module);
  117.     my $modfname = $modparts[-1];
  118.  
  119.     # Some systems have restrictions on files names for DLL's etc.
  120.     # mod2fname returns appropriate file base name (typically truncated)
  121.     # It may also edit @modparts if required.
  122.     $modfname = &mod2fname(\@modparts) if defined &mod2fname;
  123.  
  124.     my $modpname = join('/',@modparts);
  125.  
  126.     print STDERR "DynaLoader::bootstrap for $module ",
  127.         "(auto/$modpname/$modfname.$dl_dlext)\n" if $dl_debug;
  128.  
  129.     foreach (@INC) {
  130.     chop($_ = VMS::Filespec::unixpath($_)) if $Is_VMS;
  131.     my $dir = "$_/auto/$modpname";
  132.     next unless -d $dir; # skip over uninteresting directories
  133.  
  134.     # check for common cases to avoid autoload of dl_findfile
  135.     my $try = "$dir/$modfname.$dl_dlext";
  136.     last if $file = ($do_expand) ? dl_expandspec($try) : (-f $try && $try);
  137.  
  138.     # no luck here, save dir for possible later dl_findfile search
  139.     push @dirs, $dir;
  140.     }
  141.     # last resort, let dl_findfile have a go in all known locations
  142.     $file = dl_findfile(map("-L$_",@dirs,@INC), $modfname) unless $file;
  143.  
  144.     croak("Can't locate loadable object for module $module in \@INC (\@INC contains: @INC)")
  145.     unless $file;    # wording similar to error from 'require'
  146.  
  147.     my $bootname = "boot_$module";
  148.     $bootname =~ s/\W/_/g;
  149.     @dl_require_symbols = ($bootname);
  150.  
  151.     # Execute optional '.bootstrap' perl script for this module.
  152.     # The .bs file can be used to configure @dl_resolve_using etc to
  153.     # match the needs of the individual module on this architecture.
  154.     my $bs = $file;
  155.     $bs =~ s/(\.\w+)?$/\.bs/; # look for .bs 'beside' the library
  156.     if (-s $bs) { # only read file if it's not empty
  157.         print STDERR "BS: $bs ($^O, $dlsrc)\n" if $dl_debug;
  158.         eval { do $bs; };
  159.         warn "$bs: $@\n" if $@;
  160.     }
  161.  
  162.     # Many dynamic extension loading problems will appear to come from
  163.     # this section of code: XYZ failed at line 123 of DynaLoader.pm.
  164.     # Often these errors are actually occurring in the initialisation
  165.     # C code of the extension XS file. Perl reports the error as being
  166.     # in this perl code simply because this was the last perl code
  167.     # it executed.
  168.  
  169.     my $libref = dl_load_file($file, $module->dl_load_flags) or
  170.     croak("Can't load '$file' for module $module: ".dl_error()."\n");
  171.  
  172.     push(@dl_librefs,$libref);  # record loaded object
  173.  
  174.     my @unresolved = dl_undef_symbols();
  175.     if (@unresolved) {
  176.     require Carp;
  177.     Carp::carp("Undefined symbols present after loading $file: @unresolved\n");
  178.     }
  179.  
  180.     my $boot_symbol_ref = dl_find_symbol($libref, $bootname) or
  181.          croak("Can't find '$bootname' symbol in $file\n");
  182.  
  183.     my $xs = dl_install_xsub("${module}::bootstrap", $boot_symbol_ref, $file);
  184.  
  185.     push(@dl_modules, $module); # record loaded module
  186.  
  187.     # See comment block above
  188.     &$xs(@args);
  189. }
  190.  
  191.  
  192. #sub _check_file {   # private utility to handle dl_expandspec vs -f tests
  193. #    my($file) = @_;
  194. #    return $file if (!$do_expand && -f $file); # the common case
  195. #    return $file if ( $do_expand && ($file=dl_expandspec($file)));
  196. #    return undef;
  197. #}
  198.  
  199.  
  200. # Let autosplit and the autoloader deal with these functions:
  201.